package com.cheng.example.atguigu.view2;


/**
 * 005、volatile不保证原子性测试
 */
class Client05_MyData {
    int number = 0;
    public void addPlusPlus() {
        number++;
    }
}

public class Client05 {
    public static void main(String[] args) {
        Client05_MyData myData = new Client05_MyData();
        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    myData.addPlusPlus();
                }
            }).start();
        }
        while (Thread.activeCount() > 2) {
            Thread.yield();
        }
        System.out.println(myData.number);
    }

}


